Skip to content

fix(assistant): 切换免费模型 Intern-S1 → GLM-4.6V-Flash + 加关闭按钮 (#285)#293

Merged
longsizhuo merged 1 commit intomainfrom
fix/chatbot-unauthorized-and-close-285
Apr 16, 2026
Merged

fix(assistant): 切换免费模型 Intern-S1 → GLM-4.6V-Flash + 加关闭按钮 (#285)#293
longsizhuo merged 1 commit intomainfrom
fix/chatbot-unauthorized-and-close-285

Conversation

@longsizhuo
Copy link
Copy Markdown
Member

Closes

#285

问题

  1. 在归档分类(Classified Archives)页点投稿,聊天机器人发消息直接报 unauthorized,建议问题点击也无响应。
  2. 聊天窗口没有显式关闭/最小化按钮,边框一直悬浮遮挡页面内容。

根因

  1. 默认免费模型 Intern-S1 的 INTERN_KEY 已过期 → 本地兜底推理也 401 → 错误文案透传到 UI。
  2. 模态框当前只能靠 Trigger 按钮(变成 ChevronDown 形态)/点击外部/Esc 关闭,用户发现不了。
  3. Java 后端 /openai/responses/stream@SaCheckLogin,匿名用户必 401,但 Next.js 代理仍会尝试再超时 5 秒,造成噪音。

改动

  • 切换免费模型lib/ai/providers/intern.ts 底层改接智谱 GLM-4.6V-Flash(128K 上下文、多模态、免费),走 OpenAI-compatible 接口,用 ZHIPU_API_KEY。provider 名保留 intern 避免 localStorage 迁移。
  • 匿名跳过后端代理/api/chat/route.ts 发现没有 x-satoken 时直接短路到本地 GLM 推理,省 5s 超时,避免后端 401 文案干扰。
  • 模态框关闭按钮assistant-modal.tsx 改用受控 open 状态,右上角新增 X 按钮,点击关闭窗口。
  • 文案与致谢:SettingsDialog 更新为 "GLM-4.6V-Flash (Free)",保留对上海 AI Lab 书生 Intern-S1 首发算力赞助的致谢。
  • 环境变量.env.sample 新增 ZHIPU_API_KEY 占位。

⚠️ 部署须知

Vercel 环境变量必须新增 ZHIPU_API_KEY(从 https://open.bigmodel.cn/ 获取),否则线上还是会 401。INTERN_KEY 可以保留但实际不再使用。

测试

  • pnpm typecheck 通过
  • pnpm lint 无新增 error(既存 warnings 不动)
  • 本地 dev 验证:登出状态发消息 → GLM 正常回流
  • 本地 dev 验证:右上 X 按钮点击后窗口关闭
  • 生产部署后验证匿名用户聊天可用

后续可做(基于 GLM-4.6V-Flash 能力,单独 PR)

  • 图片输入:读者粘贴/拖拽截图问文档里的图或公式
  • 思考模式 toggle:深度推理开关(thinking: { type: "enabled" }
  • 更长上下文:利用 128K 窗口把相关章节一起喂入

- 免费模型 Intern-S1 key 过期导致匿名用户发消息报 unauthorized。
  改接智谱 GLM-4.6V-Flash(128K 上下文、多模态、免费),用
  ZHIPU_API_KEY 走 OpenAI-compatible 接口。保留 provider 名 `intern`
  避免 localStorage 迁移。
- 匿名请求跳过 Java 后端代理:/openai/responses/stream 有 @SaCheckLogin,
  匿名必 401,短路省 5s 超时、避免错误文案透传。
- 模态框右上角加 X 关闭按钮(改用受控 open state),解决
  "边框悬浮但找不到关闭入口" 的 UX 问题。
- SettingsDialog 文案更新:标注 GLM-4.6V-Flash,保留对书生
  Intern-S1 首发算力赞助的致谢。
- .env.sample 新增 ZHIPU_API_KEY 占位。

Closes #285
Copilot AI review requested due to automatic review settings April 16, 2026 19:31
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
involutionhell-github-io Building Building Preview, Comment Apr 16, 2026 7:31pm
website-preview Building Building Preview, Comment Apr 16, 2026 7:31pm

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在修复文档站点右下角 AI Assistant 在匿名场景下对话报 unauthorized、建议点击无响应的问题,并为聊天窗口补充明确的关闭入口;同时将默认“免费兜底模型”从已失效的 Intern-S1 切换到智谱 GLM-4.6V-Flash,以恢复可用性并减少后端代理带来的超时噪音。

Changes:

  • intern provider 的底层实现切换为智谱 GLM-4.6V-Flash(开发环境可选 Deepseek)。
  • Chat API 在无 x-satoken 时跳过 Java 后端代理,直接走本地推理路径以避免 5s 超时与 401 干扰。
  • Assistant 模态框改为受控 open 状态,并新增右上角关闭(X)按钮;同步更新设置页文案与新增 ZHIPU_API_KEY 示例配置。

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/ai/providers/intern.ts 将免费默认模型实现迁移到 Zhipu OpenAI-compatible 接口(GLM-4.6V-Flash),保留 intern 标识以避免存量设置迁移。
app/components/assistant-ui/assistant-modal.tsx 引入受控开关状态,并在模态框内容区域添加显式关闭按钮。
app/components/assistant-ui/SettingsDialog.tsx 更新 provider 展示文案为 GLM-4.6V-Flash,并调整“intern”说明区块内容。
app/api/chat/route.ts 针对匿名请求短路跳过后端代理,减少超时与 401 对 UI 的影响。
.env.sample 增加 ZHIPU_API_KEY 占位并标注 INTERN_KEY 已弃用。

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/api/chat/route.ts
Comment on lines +40 to +42
if (!hasAuthToken) {
throw new Error("Anonymous request, skip backend proxy.");
}
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里用 throw 触发 fallback 会导致所有匿名请求都进入 catch 分支并打印带 stack 的 warn 日志(且文案是“Java Backend unavailable...”),实际会在生产环境造成大量噪音。建议改为显式的 if 分支直接跳过代理(不抛错、不进入 catch),或在 catch 中对匿名场景单独处理为低噪日志/不记录 error 对象。

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +29
const glm = createOpenAICompatible({
name: "zhipu",
baseURL: "https://open.bigmodel.cn/api/paas/v4/",
apiKey: process.env.ZHIPU_API_KEY,
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createOpenAICompatible 的 apiKey 直接传入 process.env.ZHIPU_API_KEY(可能为 undefined)。当线上漏配环境变量时会变成下游 401/500,仍可能在 UI 里表现为“unauthorized/请求失败”,和本 PR 目标相悖。建议在这里显式校验 ZHIPU_API_KEY,缺失时抛出带明确指引的错误(例如提示需要在 Vercel 配置该变量),或提供可用的本地兜底。

Suggested change
const glm = createOpenAICompatible({
name: "zhipu",
baseURL: "https://open.bigmodel.cn/api/paas/v4/",
apiKey: process.env.ZHIPU_API_KEY,
const zhipuApiKey = process.env.ZHIPU_API_KEY;
if (!zhipuApiKey || zhipuApiKey.trim() === "") {
throw new Error(
"Missing required environment variable ZHIPU_API_KEY. Configure it on the server (for example in Vercel Project Settings -> Environment Variables) before using the intern provider.",
);
}
const glm = createOpenAICompatible({
name: "zhipu",
baseURL: "https://open.bigmodel.cn/api/paas/v4/",
apiKey: zhipuApiKey,

Copilot uses AI. Check for mistakes.
@longsizhuo longsizhuo merged commit b2ca53a into main Apr 16, 2026
9 of 11 checks passed
@longsizhuo longsizhuo deleted the fix/chatbot-unauthorized-and-close-285 branch April 16, 2026 19:35
longsizhuo added a commit that referenced this pull request Apr 16, 2026
Copilot 在 PR #293 指出两点,follow-up 修复:

- **app/api/chat/route.ts**:原先用 `throw new Error("Anonymous request")`
  触发 fallback,副作用是每个匿名请求都被 catch 打成带 stack 的
  "Java Backend unavailable" warn,生产日志会刷爆。改成显式 if-else 分支
  直接短路到本地推理,不抛错,只打一行 info 级日志。顺带清理了多余的
  x-satoken 三元展开。

- **lib/ai/providers/intern.ts**:原先把 process.env.ZHIPU_API_KEY 直接
  喂给 createOpenAICompatible,漏配时下游会 401/500,UI 上依旧表现为
  "unauthorized" —— 这正是 issue #285 要根治的症状,不能再放任。加了
  显式校验,缺失时抛出带 Vercel 配置指引的错误。
longsizhuo added a commit that referenced this pull request Apr 16, 2026
Copilot 在 PR #293 指出两点,follow-up 修复:

- **app/api/chat/route.ts**:原先用 `throw new Error("Anonymous request")`
  触发 fallback,副作用是每个匿名请求都被 catch 打成带 stack 的
  "Java Backend unavailable" warn,生产日志会刷爆。改成显式 if-else 分支
  直接短路到本地推理,不抛错,只打一行 info 级日志。顺带清理了多余的
  x-satoken 三元展开。

- **lib/ai/providers/intern.ts**:原先把 process.env.ZHIPU_API_KEY 直接
  喂给 createOpenAICompatible,漏配时下游会 401/500,UI 上依旧表现为
  "unauthorized" —— 这正是 issue #285 要根治的症状,不能再放任。加了
  显式校验,缺失时抛出带 Vercel 配置指引的错误。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants